﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetNewVendorIdDataAction : BestLifeDataAction<string>
    {

        public BestLifeGetNewVendorIdDataAction()
        {
            
        }

        public override string Body(SqlConnection PConn)
        {
            try
            {

                string LvQuery = "Select dbo.NextVendorID()";
                SqlCommand LvCommand = new SqlCommand(LvQuery, PConn);
                SqlDataReader LvReader = LvCommand.ExecuteReader();
                string LvVendorId = "";
                while (LvReader.Read())
                {
                    try
                    {
                        LvVendorId = LvReader.GetValue(0).ToString();
                    }
                    catch (Exception)
                    {
                        LvVendorId = "";
                    }
                }
                return LvVendorId;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
